﻿#region Header
// ------------------------ Licence / Copyright ------------------------
// 
// ScrumTable for Scrum Meeting Support
// Copyright © HSR - Hochschule für Technik Rapperswil
// All Rights Reserved
// 
// Author:
//  Michael Gfeller Silvan Gehrig Patrick Boos
// 
// ---------------------------------------------------------------------
#endregion

#region Usings

#endregion

using System;

namespace ScrumTable.Common.Collections
{
    /// <summary>
    /// Gets a min max range
    /// </summary>
    [Serializable]
    public struct Range
    {
        /// <summary>
        /// max value in the range
        /// </summary>
        public double Max { get; set; }
        /// <summary>
        /// min value in the range
        /// </summary>
        public double Min { get; set; }

        /// <summary>
        /// If true then the range checks if the value is not null
        /// </summary>
        public bool IsNullRange { get; set; }

        /// <summary>
        /// Initializes a new instance of the <see cref="Range"/> struct.
        /// </summary>
        /// <param name="min">The min value of the range.</param>
        /// <param name="max">The max value of the range.</param>
        public Range(double min, double max)
            : this()
        {
            Min = min;
            Max = max;
            IsNullRange = false;
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="Range"/> struct.
        /// if isNullRange is true then IsInRange(double? ) checks if the value is null
        /// </summary>
        /// <param name="isNullRange"></param>
        public Range(bool isNullRange)
            : this()
        {
            Min = double.MinValue;
            Max = double.MaxValue;
            IsNullRange = isNullRange;
        }

        /// <summary>
        /// Checks if the value is in range (inclusive boundaries)
        /// or
        /// if the value is null (NullRange)
        /// </summary>
        /// <param name="value"></param>
        /// <returns></returns>
        public bool IsInRange(double? value)
        {
            if (IsNullRange)
            {
                return !value.HasValue;
            }
            if (!value.HasValue)
            {
                return false;
            }
            return value <= Max && value >= Min;
        }


    }
}
